var img = document.querySelector("img")
var currentIndex = 1
var timerId = null

function start() {
    
    if (timerId) return
    // 每隔1秒自动切换图片
    timerId = setInterval(function () {
        currentIndex++
        if (currentIndex === 5) {
            currentIndex = 1
        }
        img.src = `./img/${currentIndex}.jpeg`
    }, 1000)

}

function end() {
    clearInterval(timerId)
    timerId = null
}


// 当鼠标移动到元素上时停止切换，移出后开始切换
img.addEventListener('mouseenter', start)
img.addEventListener('mouseleave', end)

